import 'package:flutter/widgets.dart';

class TrainingPageTranslation {
  static final delegate = _TrainingPageTranslationDelegate();

  static TrainingPageTranslation of(BuildContext context) {
    return Localizations.of(context, TrainingPageTranslation);
  }

  late String _languageCode;

  Future<void> load(Locale locale) async {
    _languageCode = locale.languageCode;
  }

  String _resolve(Map<String, String> translations) {
    return translations[_languageCode]!;
  }

  String get summarizingCardTitle {
    return _resolve(const {
      'ru': 'Отличная работа!',
      'en': 'Great job!',
    });
  }
}

class _TrainingPageTranslationDelegate extends LocalizationsDelegate<TrainingPageTranslation> {
  @override
  bool isSupported(Locale locale) => const ['ru', 'en'].contains(locale.languageCode);

  @override
  bool shouldReload(LocalizationsDelegate<TrainingPageTranslation> old) => false;

  @override
  Future<TrainingPageTranslation> load(Locale locale) async {
    final translation = TrainingPageTranslation();
    await translation.load(locale);
    return translation;
  }
}
